package com.longcai.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.longcai.entity.auth.SysShopsPermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author ZJ
 * @since 2019-03-16
 */
@Mapper
@Repository
public interface SysShopsPermissionMapper extends BaseMapper<SysShopsPermission> {

    @Select("select distinct p.* from sys_shops_permission p inner join sys_shops_role_permission rp on p.id = rp.permissionId inner join sys_shops_role_user ru on ru.roleId = rp.roleId where ru.userId = #{userId} order by p.sort")
    List<SysShopsPermission> listByUserId(String userId);

    @Select("select * from sys_shops_permission t where t.type = 1 order by t.sort")
    List<SysShopsPermission> listParents();

    @Select("select p.* from sys_shops_permission p inner join sys_shops_role_permission rp on p.id = rp.permissionId where rp.roleId = #{roleId} order by p.sort")
    List<SysShopsPermission> listByRoleId(String roleId);
}
